package com.jeeplus.modules.infor.util;

import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.modules.fleet.entity.Motorcade;
import com.jeeplus.modules.fleet.entity.VehicleInformation;
import com.jeeplus.modules.fleet.mapper.MotorcadeMapper;
import com.jeeplus.modules.fleet.mapper.VehicleInformationMapper;
import com.jeeplus.modules.infor.entity.*;
import com.jeeplus.modules.infor.mapper.*;
import com.jeeplus.modules.sys.utils.UserUtils;

import java.util.List;

/**
 * Created by Administrator on 2018/1/2.
 */

public class ImportUtil {
    private static ProjectMapper projectMapper = SpringContextHolder.getBean(ProjectMapper.class);
    private static StorageMapper storageMapper= SpringContextHolder.getBean(StorageMapper.class);
    private static StoreMapper storeMapper= SpringContextHolder.getBean(StoreMapper.class);
    private static GoodsMapper goodsMapper= SpringContextHolder.getBean(GoodsMapper.class);
    private static MaterialTypeMapper materialType= SpringContextHolder.getBean(MaterialTypeMapper.class);
    private static LocationMapper locationMapper= SpringContextHolder.getBean(LocationMapper.class);
    private static MotorcadeMapper motorcadeMapper= SpringContextHolder.getBean(MotorcadeMapper.class);
    private static TruckTypeMapper truckTypeMapper= SpringContextHolder.getBean(TruckTypeMapper.class);
    private static  DepartmentMapper departmentMapper=SpringContextHolder.getBean(DepartmentMapper.class);
    private static  PositionMapper positionMapper=SpringContextHolder.getBean(PositionMapper.class);
    private static VehicleInformationMapper vehicleInformationMapper=SpringContextHolder.getBean( VehicleInformationMapper.class);
    private static  SettlementMapper  settlementMapper=SpringContextHolder.getBean(  SettlementMapper.class);
    private static StartMapper  startMapper=SpringContextHolder.getBean(  StartMapper.class);
    private static WidthMapper   widthMapper=SpringContextHolder.getBean(   WidthMapper.class);
    private static TakeAddressMapper   takeAddressMapper=SpringContextHolder.getBean( TakeAddressMapper.class);
    private static NewCustomersMapper   newCustomersMapper=SpringContextHolder.getBean( NewCustomersMapper.class);
    private static NewWidthMapper   newWidthMapper=SpringContextHolder.getBean( NewWidthMapper.class);



    public static Project getProject(String name){
   return projectMapper.findUniqueByProperty("name",name);
   }

    public static Storage getStorage(String s) {
        Storage storage=new Storage();
        storage.setProjectName(UserUtils.getUseroffice());
        storage.setName(s);
        return storageMapper.findList(storage).get(0);
    }

    public static Store getStore(String s) {
        Store store=new Store();
        store.setName(s);
        store.setProject(projectMapper.findUniqueByProperty("name",UserUtils.getUseroffice()));
        return storeMapper.findList(store).get(0);
    }

    public static Goods getGoodsByName(String s) {
        Goods g=new Goods();
        g.setProject(UserUtils.getUseroffice());
        g.setName(s);
        return goodsMapper.findList(g).get(0);
    }

    public static MaterialType getType(String s) {
        return materialType.findUniqueByProperty("name",s);
    }

    public static Location getLocation(String s) {
        Location l=new Location();
        l.setProjectName(UserUtils.getUseroffice());
        l.setName(s);
        return locationMapper.findList(l).get(0);
    }

    public static Motorcade getMotorcade(String s) {
        return motorcadeMapper.findUniqueByProperty("name",s);
    }

    public static TruckType getTruckType(String s) {return truckTypeMapper.findUniqueByProperty("type",s);

    }

    public static Department getDepartment(String s) {
        Department d=new Department();
        d.setName(s);
        d.setProject(projectMapper.findUniqueByProperty("name",UserUtils.getUseroffice()));
       d= departmentMapper.findList(d).get(0);
       return d;
    }

    public static Position getPosition(String s) {
        Position p=new Position();
        p.setName(s);
        p.setProjectName(UserUtils.getUseroffice());
        return positionMapper.findList(p).get(0);
    }

    public static VehicleInformation getVehicleInformation(String s) {
        VehicleInformation v=new VehicleInformation();
        v.setProjectName(UserUtils.getUseroffice());
        v.setLicense(s);
        return vehicleInformationMapper.findList(v).get(0);
    }

    public static Settlement getSettlement(String s) {
        Settlement se=new Settlement();
        se.setName(s);
        se.setPro(UserUtils.getUseroffice());
        return settlementMapper.findList(se).get(0);
    }

    public static Start getStart(String s) {
        Start ss=new Start();
        ss.setPro(UserUtils.getUseroffice());
        ss.setName(s);
        return  startMapper.findList(ss).get(0);
    }

    public static Width getWidth(String s) {
        Width w=new Width();
        w.setProject(UserUtils.getUseroffice());
        w.setWidth(s);
        return  widthMapper.findList(w).get(0);
    }
    public static NewWidth getnewWidth(String s) {
        NewWidth w=new NewWidth();
        w.setPro(UserUtils.getUseroffice());
        w.setWidth(s);
        return  newWidthMapper.findList(w).get(0);
    }

    public static TakeAddress getTakeAddress(String s) {
        TakeAddress t=new TakeAddress();
        t.setPro(UserUtils.getUseroffice());
        t.setStore(s);
        return takeAddressMapper.findList(t).get(0);
    }

    public static NewCustomers getCustomer(String s) {
        NewCustomers n=new NewCustomers();
        n.setDwmc(s);
        n.setPro(UserUtils.getUseroffice());
        return newCustomersMapper.findList(n).get(0);
    }
}
